"""
管理员接口层
"""
from db import models

#管理员注册
def register(user_name,password):
    #判断用户是否存在
    admin_obj = models.Admin.self_select(user_name)
    if admin_obj:
        return False,"用户已存在!"
    
    obj=models.Admin(user_name,password)
    obj.self_save()
    return True,"用户创建成功！"

#管理员登录
# def login(user_name,password):
#     #判断用户是否存在
#     login_obj=models.Admin.self_select(user_name)
#     if not login_obj:
#         return False,"用户未注册！"
#     if password == login_obj.password:
#         return True,"登陆成功!"
#     return False,"密码错误，登录失败！"

#管理员创建学校
def create_school(name,addr,admin_name):
    #判断学校是否存在
    school_obj = models.School.self_select(name)
    if school_obj:
        return False,"学校已存在，创建失败！"
    #创建学校
    admin_obj = models.Admin.self_select(admin_name)
    admin_obj.create_school(name,addr)
    return True,f"管理员[{admin_name}]创建了[{name}]学校"

#管理员创建课程
def create_crouse(crouse_name,crouse_price,crouse_week,admin_dic,school_name):
    #判断课程是否存在
    school_obj = models.School.self_select(school_name)
    if crouse_name in school_obj.crouse:
        return False,"课程已创建"
    admin_obj = models.Admin.self_select(admin_dic)
    admin_obj.create_crouse(crouse_name,crouse_price,crouse_week,school_obj)
    return True,f"管理员{admin_dic}在{school_name}校区创建了{crouse_name}课程,"

#管理员创建老师
def create_teather(teather_name,admin_dic,chushipassword = "123"):
    teanther_obj = models.Teather.self_select(teather_name)
    if teanther_obj:
        return False,"教师已经创建!"
    admin_obj = models.Admin.self_select(admin_dic)
    admin_obj.create_teather(teather_name,chushipassword)
    return True,f"管理员[{admin_dic}]成功创建教师[{teather_name}]"